package cn.pfz.controller;

import cn.pfz.Service.IBusinessService;
import cn.pfz.Service.IConsumptionReportService;
import cn.pfz.domain.Business;
import cn.pfz.domain.BusinessReport;
import cn.pfz.query.BusinessReportQuery;
import cn.pfz.statusnum.AppointmentstatusEnum;
import cn.pfz.statusnum.ConsumptionStatusEnum;
import com.alibaba.druid.support.json.JSONUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 普发忠
 * @Date: 2021/09/14/9:51
 */
@Controller
@RequestMapping("/Report")
public class BusinessReportController {
    
    @Autowired
    protected IConsumptionReportService consumptionReportService;
    @Autowired
    protected IBusinessService businessService;
    
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") BusinessReportQuery qo) {
        PageInfo<BusinessReport> list = consumptionReportService.list(qo);
        model.addAttribute("result", list);
        List<Business> businesses = businessService.selectAll();
        model.addAttribute("businesses", businesses);
        ConsumptionStatusEnum[] values = ConsumptionStatusEnum.values();
        model.addAttribute("consumptionStatuses", values);
        
        List<String> a1 = new ArrayList<>();
        List<Integer> a2 = new ArrayList<>();
        List<BigDecimal> a3 = new ArrayList<>();
        List<BigDecimal> a4 = new ArrayList<>();
        List<BigDecimal> a5 = new ArrayList<>();
        for (BusinessReport businessReport : list.getList()) {
            a1.add(businessReport.getGroupmethod());
            a2.add(businessReport.getCount());
            a3.add(businessReport.getTotal());
            a4.add(businessReport.getDiscount());
            a5.add(businessReport.getPay());
        }
        String groupmethod_json = JSONUtils.toJSONString(a1);
        String count_json = JSONUtils.toJSONString(a2);
        String total_json = JSONUtils.toJSONString(a3);
        String discount_json = JSONUtils.toJSONString(a4);
        String pay_json = JSONUtils.toJSONString(a5);
        
        model.addAttribute("groupmethod_json", groupmethod_json);
        model.addAttribute("count_json", count_json);
        model.addAttribute("total_json", total_json);
        model.addAttribute("discount_json", discount_json);
        model.addAttribute("pay_json", pay_json);
        
        
        return "businessReport/list";
    }
    
}
